﻿using System.Linq;
using System.Windows;
using kursovaya.Data.Context;

namespace kursovaya.Windows
{
    public partial class SearchRemoveInvWindow : Window
    {
        public SearchRemoveInvWindow()
        {
            InitializeComponent();
        }

        private void SearchButton_OnClick(object sender, RoutedEventArgs e)
        {
            string searchText = SearchTextBox.Text.Trim();

            using (var context = new DbContext())
            {
                var invs = context.Inventoryes.Where(s =>
                    s.id.ToString() == searchText
                ).ToList();

                if (invs.Any())
                {
                    InventoryDataGrid.Items.Clear();

                    foreach (var student in invs)
                    {
                        InventoryDataGrid.Items.Add(student);
                    }
                }
                else
                {
                    MessageBox.Show("Инвентарные принадлежности с указанными параметрами не найдены!",
                        "Поиск",
                        MessageBoxButton.OK,
                        MessageBoxImage.Information);
                }

                SearchTextBox.Text = "";
            }
        }

        private void RemoveButton_OnClick(object sender, RoutedEventArgs e)
        {
            DelInvWindow delInvWindow = new DelInvWindow();
            delInvWindow.Show();
        }
    }
}